<?php
// 获取数据库提交的申请

// 查询用户数据,默认是禁言的用户和冻结的账户
$page = @$_GET['page']-1;
if ($page < 0) {
	$page = 0;
}
$count = @$_GET['count'];
if ($count < 1) {
	$count = 10;
}
$key_word_uId = trim(@$_GET['key_word_uId']);
$key_word_accId = trim(@$_GET['key_word_accId']);
// 用户没有输入关键字的时候默认显示禁言用户
$where = "";
if (empty($key_word_uId) && empty($key_word_accId)) {
	$where = "OR isStop=1 ";
} else {
	if (!empty($key_word_uId)){
		$where .= "OR uid LIKE  '%{$key_word_uId}%' ";
	}
	if (!empty($key_word_accId)){
		$where .= "OR account LIKE '%{$key_word_accId}%' ";
	}
}

// 获取用户数据
$data = array();
$select= "SELECT uid,account,isAdmin,status,isStop,last_time FROM `login_tb` WHERE 1=2 ";
$limit = "LIMIT ".($page*$count).", {$count};";
$sql = $select.$where.$limit;
my_mysql_query($sql, $data);

// 获取总量
$sum = array();
$sql = "SELECT count(uid) as count FROM `login_tb` WHERE 1=2 ".$where.$limit;
my_mysql_query($sql, $sum);
$sum = $sum[0]['count'];
?>
<style type="text/css">
#table{
	text-align: center;
}
#table1{
	padding-left: 50px;
	text-align: center;
	border-bottom: 1px solid rgb(210,210,210);
}
#table1 input {
	width: 200px;
	height: 20px;
	outline: none;
}
#table td,#table th,
#table1 td,#table1 th{
	padding: 0 15px;
}

#table tr:nth-child(even){
	border-bottom: 1px dotted rgb(210,210,210);
}
.red a:link{
    color: red;
    text-decoration:none;
}
.green a:link{
    color: green;
    text-decoration:none;
}
a:visited{
    text-decoration:none;
}
a:active{
    text-decoration:underline;
}
a:hover {
    text-decoration:underline;
}
td button {
	width: 79px;
	height: 32px;
	color: white;
	font-size: 14px;
	border:none;
	outline:none;
	cursor:pointer;
	background: url(image/agree.png) 0 0 no-repeat;
}
</style>

<form action="index.php" method="GET">
<table id="table1" cellspacing="0">
	<!-- 第一行为,用户管理 -->
	<input type="hidden" name="action" value="<?php echo $action; ?>">
	<tr>
		<td align="right">UID</td>
		<td align="center"><input type="text" name="key_word_uId" value="<?php echo $key_word_uId; ?>"></td>
		<td align="right">账户</td>
		<td align="center"><input type="text" name="key_word_accId" value="<?php echo $key_word_accId; ?>"></td>
		<td align="center"> <button type="submit">搜索</button> </td>
	</tr>
</table>
</form>


<table id="table" cellspacing="0">
	<caption><h1>用户状态处理</h1></caption>
	<tr>
		<th>序号</th>
		<th>账户</th>
		<th>名称</th>
		<th>是否管理员</th>
		<th>是否冻结</th>
		<th>是否禁言</th>
		<th>最后活动时间</th>
	</tr>

	<?php
	// TODO:默认获取禁言的用户
	// uid,account,isAdmin,status,isStop,last_time

	if ($sum > 0){
		$i=1;
		foreach($data as $flink){
			$tmpid = $flink['uid'];
			echo '<tr>';
			echo '<td>'.$i++.'</td>';
			echo '<td>'.$tmpid.'</td>';
			echo '<td>'.$flink['account'].'</td>';

			// 设置管理员
			if ($flink['isAdmin']) {
				$value = 0;
				$class = "red";
				$msg   = "解除管理员";
			}else{
				$value = 1;
				$class = "green";
				$msg   = "设置管理员";
			}
			echo '<td class="'.$class.'"><a href="user_handler.php?method=setAdmin&value='.$value.'&uid='.$tmpid.'">'.$msg.'</a></td>';

			// 冻结账户
			if ($flink['status']) {
				$value = 0;
				$class = "green";
				$msg   = "账户解冻";
			}else{
				$value = 1;
				$class = "red";
				$msg   = "账户冻结";
			}
			echo '<td class="'.$class.'"><a href="user_handler.php?method=setStatus&value='.$value.'&uid='.$tmpid.'">'.$msg.'</a></td>';

			// 禁言用户
			if ($flink['isStop']) {
				$value = 0;
				$class = "green";
				$msg   = "取消禁言";
			}else{
				$value = 1;
				$class = "red";
				$msg   = "设置禁言";
			}
			echo '<td class="'.$class.'"><a href="user_handler.php?method=shutUp&value='.$value.'&uid='.$tmpid.'">'.$msg.'</a></td>';
			echo '<td>'.date('Y-m-d',$flink['last_time']).'</td>';
			echo '</tr>';
		}
	}
	?>
</table>

<div class="toolbar">
	<form action="index.php" method="GET">
		<input type="hidden" name="action" value="<?php echo $action; ?>">
		<input type="hidden" name="key_word_uId" value="<?php echo $key_word_uId; ?>">
		<input type="hidden" name="key_word_accId" value="<?php echo $key_word_accId; ?>">
		共有<?php echo ceil($sum/$count);?>页,每页有
		<input type="text" size="3" name="count" value="<?php echo $count; ?>">条信息
		当前第<?php echo ($page+1);?>页,跳到第
		<input type="text" size="3" name="page" value="<?php echo $page+2; ?>">页
		<input type="submit" value="GO">
	</form>
</div>
